package cn.shengchao.rule.condition.matchType;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.shengchao.rule.condition.valueType.IValueType;

import java.util.Date;

/**
 * @program: examstarapi
 * @description: 操作符=
 * @author: Xiong weiqiang
 * @create: 2025-04-11 14:32
 */
public class MatchTypeDateRangeIn implements IMatchType{
    @Override
    public String getMatchTypeKey() {
        return IMatchType.DATE_RANGE_IN;
    }

    @Override
    public String getMatchTypeValue() {
        return "在日期区间内";
    }

    @Override
    public boolean isMatch(String targetValue, String matchValue, IValueType valueType) {
        switch (valueType.valueTypeKey()) {
            case IValueType.TYPE_DATE -> {
                if (matchValue.indexOf(",")<=0){
                    System.out.println("未合格的比对值"+IValueType.TYPE_DATE+":"+matchValue);
                    return false;}
                String[] days = matchValue.split(",");
                if (days.length == 2){
                    long matchDay1 = Long.parseLong(days[0]);
                    long matchDay2 = Long.parseLong(days[1]);
                    long matchInt;
                    if (StrUtil.isBlank(targetValue)){
                        matchInt =System.currentTimeMillis();
                    }else {
                        matchInt = Long.parseLong(targetValue);
                    }
                    return matchDay1 <= matchInt && matchDay2 >=matchInt;
                }
            }
            case IValueType.TYPE_DAY ->  {
                if (matchValue.indexOf(",")<=0){
                    System.out.println("未合格的比对值"+IValueType.TYPE_DAY+":"+matchValue);
                    return false;}
                String[] days = matchValue.split(",");
                if (days.length == 2){
                    int matchDay1 = Integer.parseInt(days[0]);
                    int matchDay2 = Integer.parseInt(days[1]);
                    int matchInt;
                    if (StrUtil.isBlank(targetValue)){
                        String dateStr = DateUtil.format(new Date(),"yyyyMMdd");
                        matchInt = Integer.parseInt(dateStr);
                    }else {
                        matchInt = Integer.parseInt(targetValue);
                    }
                    return matchDay1 <= matchInt && matchDay2 >=matchInt;
                }
                return false;
            }
            default ->{return false;}
        };
        return false;
    }


}